﻿function initLeftMenu() {
    $("#root ul").each(function () { $(this).css("display", "none"); });
    $("#root .category").click(function () {
        var childid = "#" + $(this).attr("childid");
        if ($(childid).css("display") == "none") { $(childid).css("display", "block"); }
        else { $(childid).css("display", "none"); }
        if ($(this).hasClass("cat_close")) { $(this).removeClass("cat_close").addClass("cat_open"); }
        else { $(this).removeClass("cat_open").addClass("cat_close"); }
    });
}

function initNumberInputDialog() {
    var dialog = $("#NumberInputDialog");
    dialog.dialog({
        modal: true,
        autoOpen: false
    });
}

function showAddUpPointDialog(msg, frm) {
    var dialog = $("#NumberInputDialog");
    var frm = $("#" + frm);
    frm.attr("action", "/Admin/Member/AddUpPoint");
    dialog.find("input[type=submit]").click(function () {
        frm.find("#inputNumber").val(dialog.find("input[type=text]").val());
        frm.submit();
        //dialog.dialog("close");
    });
    dialog.find("label").text(msg);
    dialog.dialog("open");
    return false;
}


function showSubtractUpPointDialog(msg, frm) {
    var dialog = $("#NumberInputDialog");
    var frm = $("#" + frm);
    frm.attr("action", "/Admin/Member/SubtractUpPoint");
    dialog.find("input[type=submit]").click(function () {
        frm.find("#inputNumber").val(dialog.find("input[type=text]").val());
        frm.submit();
        //dialog.dialog("close");
    });
    dialog.find("label").text(msg);
    dialog.dialog("open");
    return false;
}

function Hide_Show_SubMenu(idSubMenu, idParentMenu) {
    var subMenu = "#" + idSubMenu;
    var arrStr = subMenu.split("_");
    var parentMenu2 = "";
    if (arrStr != null)
        for (var i = 0; i < arrStr.length - 1; i++) {
            parentMenu2 = parentMenu2 + arrStr[i];
        }
    //  $("li#id_name a:firt") --> Lấy phần tử a thứ nhất trong khối li mà có id = id_name
    var parentMenu = "li#" + idParentMenu + " a:first";
    if ($(subMenu).css("display") == "none") {
        if (parentMenu2 != null && parentMenu2 != "")
            $(parentMenu2).css("display", "none");
        $(subMenu).css("display", "block");
        $(parentMenu).addClass("menu_select");
    }
    else {
        $(subMenu).css("display", "none");
        if (parentMenu2 != null && parentMenu2 != "")
            $(parentMenu2).css("display", "none");
        $(parentMenu).removeClass("menu_select");
    }
}

function Hide_Show_SubMenu_Refresh(idSubMenu, idParentMenu, li1, li2, li3) {
    var subMenu = "#" + idSubMenu;
    var parentMenu = "#" + idParentMenu;
    var _li1 = "li#" + li1 + " a:first";
    var _li2 = "li#" + li2 + " a:first";
    var _li3 = "li#" + li3 + " a:first";
    $(subMenu).css("display", "block");
    $(parentMenu).css("display", "block");
    $(_li1).addClass("menu_select");
    $(_li2).addClass("menu_select");
    $(_li3).addClass("menu_select");
}


function LoadSubMenu(cateId) {
    $.ajax({
        type: "POST",
        url: "/Admin/LoadSubMenu",
        data: "cateId=" + cateId,
        success: function (result) {
            if (result.success) {
                alert(result.data[1]);
            }
        },
        error: function (req, status, error) {
            alert("Sorry! We could not receive your feedback at this time.");
        }
    });
}


function deleteMember() {
    var input = document.getElementsByTagName("input");
    var spid = 0;
    for (var i = 0; i < input.length; i++) {
        if (input[i].checked == true) {
            spid = input[i].value;
            break;
        }
    }
    $.ajax({
        type: "POST",
        url: "/Member/DeleteMember",
        data: "id=" + spid,
        success: function (result) {
            alert("xóa người dùng thành công !");
            location.reload(true);

        },
        error: function (req, status, error) {
            alert("Sorry! We could not receive your feedback at this time.");
        }
    });
}


function sendMailMember() {
    var input = document.getElementsByTagName("input");

    var spid = 0;
    for (var i = 0; i < input.length; i++) {
        if (input[i].checked == true) {
            spid = input[i].value;
            break;
        }
    }
    var ff = document.getElementById("ModalLoader");
    $.ajax({
        type: "POST",
        url: "/Member/SendMailMember",
        data: "id=" + spid + "&content=" + $('.ModalNoiDung').val(),
        beforeSend: function (xhr) {
            ff.innerHTML = "<img  src='../../../Content/Images/fb_loader.gif' />";
        },
        success: function (result) {
            alert("Gởi email thành công !");
            ff.innerHTML = "Hoàn thành";
        },
        error: function (req, status, error) {
            alert("Sorry! We could not receive your feedback at this time.");
        }
    });
}


$(document).ready(function () {

    var triggers = $(".modalInput").overlay({

        // some mask tweaks suitable for modal dialogs
        mask: {
            color: '#ebecff',
            loadSpeed: 200,
            opacity: 0.9
        },

        closeOnClick: false
    });

    var buttons = $("#yesno button").click(function (e) {

        // get user input
        var yes = buttons.index(this) === 0;

        // do something with the answer
        triggers.eq(0).html("You clicked " + (yes ? "yes" : "no"));
    });

    $(".prompt form").submit(function (e) {

        // close the overlay
        triggers.eq(1).overlay().close();
        // get user input
        var input = $("input", this).val();

        // do something with the answer
        triggers.eq(1).html(input);

        // do not submit the form
        return e.preventDefault();
    });
});
  